import { AEvent } from "../../../../../Core/Module/EventSystem/IEvent";
import { EventAttribute, GetParentTypeOf, GetTypeOf } from "../../../../../Decorator/Decorator";
import { ETTask } from "../../../../../Support/Share/Lib/Async/ETTask";
import { NetClientComponentOnRead } from "../../../../Model/Client/Module/Message/NetClientComponent";
import { IResponse } from "../../../../Model/Share/Module/Message/IMessage";
import { MessageDispatcherComponent } from "../../../../Model/Share/Module/Message/MessageDispatcherComponent";

@EventAttribute(NetClientComponentOnRead)
export class NetClientComponentOnReadEvent extends AEvent<NetClientComponentOnRead> {

    async Run(args: NetClientComponentOnRead) {
        let session = args.Session;
        let message = args.Message;

        // console.log(`NetClientComponentOnReadEvent`);
        // console.log(GetTypeOf(message));
        // console.log(message);

        if (GetParentTypeOf(message) == GetTypeOf(IResponse)) {
            let response = message as IResponse;
            session.OnResponse(response);
            return;
        }
        // 普通消息或者是Rpc请求消息
        MessageDispatcherComponent.Instance.Handle(session, message);
        await ETTask.CompletedTask;
    }

}